package acm.usa1995.midcentral;

import java.math.BigInteger;
import java.util.Scanner;

/*
 * p1948
 * ACM USA Mid Central 
 */

public class p1948 {

	static String s, tmp;
	static int fr, to;
	static BigInteger num;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			s = scanner.next();
			tmp = scanner.next();
			fr = Integer.parseInt(tmp);
			tmp = scanner.next();
			to = Integer.parseInt(tmp);
			num = new BigInteger(s, fr);
			tmp = tmp.toUpperCase();
			tmp = num.toString(to);
			int len = tmp.length();
			if (len > 7) {
				System.out.println("  ERROR");
			}
			else {
				int com = 7-len;
				for (int i=0;i<com;++i) {
					System.out.print(" ");
				}
				System.out.println(tmp.toUpperCase());
			}
		}

	}

}
